package com.ar4j.handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;


/**
 * Describes an active record lookup method (findBy, findAllBy, countBy, native SQL, named query) 
 */
public class LookupMethodMetadata {
  private LookupMethodType lookupMethodType;
  private boolean isForUpdate;
  private Collection<String> parameters;
  private Map<String, Object> defaultParameters;
  private boolean isLastArgumentPagination;
  private String sqlQuery;
  private String queryName;
  
  public LookupMethodMetadata() {
    this.isForUpdate = false;
    this.parameters = new ArrayList<String>();
    this.defaultParameters = new LinkedHashMap<String, Object>();
    this.isLastArgumentPagination = false;
  }
  
  public LookupMethodType getLookupMethodType() {
    return lookupMethodType;
  }

  public void setLookupMethodType(LookupMethodType lookupMethodType) {
    this.lookupMethodType = lookupMethodType;
  }

  public boolean getIsForUpdate() {
    return isForUpdate;
  }

  public void setIsForUpdate(boolean isForUpdate) {
    this.isForUpdate = isForUpdate;
  }

  public Collection<String> getParameters() {
    return parameters;
  }

  public void setParameters(Collection<String> parameters) {
    this.parameters = parameters;
  }

  public Map<String, Object> getDefaultParameters() {
    return defaultParameters;
  }

  public void setDefaultParameters(Map<String, Object> defaultParameters) {
    this.defaultParameters = defaultParameters;
  }

  public boolean getIsLastArgumentPagination() {
    return isLastArgumentPagination;
  }

  public void setIsLastArgumentPagination(boolean isLastArgumentPagination) {
    this.isLastArgumentPagination = isLastArgumentPagination;
  }
  
  public String getSqlQuery() {
    return sqlQuery;
  }

  public void setSqlQuery(String sqlQuery) {
    this.sqlQuery = sqlQuery;
  }

  public String getQueryName() {
    return queryName;
  }

  public void setQueryName(String queryName) {
    this.queryName = queryName;
  }



  public static enum LookupMethodType {
    FIND_BY     ("findBy"),
    FIND_ALL_BY ("findAllBy"),
    COUNT_BY    ("countBy"),
    NATIVE_SQL  (""),
    NAMED_QUERY (""),
    EXISTS_BY    ("existsBy");
    
    private String methodNamePrefix;
    private LookupMethodType(String methodNamePrefix) { this.methodNamePrefix = methodNamePrefix; }
    public String getMethodNamePrefix() { return methodNamePrefix; }
  }
}
